home *** CD-ROM | disk | FTP | other *** search
- /*
- CopyScene.rexx
-
- Copyright (C) 1994 Earl C. Terwilliger
- Phone (606)-723-5718
-
- Internet: AISTERWI@ACS.EKU.EDU
- Conmpuserve: 70575,1330
-
- Non-Commercial USE granted to ALL !!!
-
- One of the problems with giving a LW scene to someone else is
- that you have to give the other files that are referenced in
- the scene file and referenced in the object files (such as
- texture and reflection maps) too. You can easily forget to
- include a file when copying your scene, image and object files
- to diskette. Even if you do manage to get all the files, the
- references to them in the scene and object files may not have
- the correct drive:directory reference. The person using the
- scene and objects will have to choose the alternate
- drive:directory when in LW layout.
-
- CopyScene.rexx remedies that situation by reading the scene
- file and copying the referenced files for you. It also, when
- copying the scene file, modifies the copy to point to the new
- destination of the copied files. Also copied and modified in
- this same manner are any object files because of references to
- texture maps and reflection maps. (The original scene and
- objects files are not modified, they are only read.) Any images
- referenced by the object files are copied to the destination also.
-
- Syntax: rx CopyScene [drive:directory/]LW-Scene-File [drive:directory]
-
- Note: The source file parameter must exist (1st parameter) and
- you must either assign LW: to a drive:directory (which
- will be used as a default destination if none is specified)
- or you must specify a second parameter which will be used
- as the destination Drive:[directory]
-
- Notice that the parameters in [] are optional. The only necessary
- parameter is the scene file name. If you do not specify a destination
- drive:directory (or just drive:) you must assign LW: to a drive
- and/or directory before running the CopyScene script.
-
- Sub-directories are created (if they do not exist) in the destination
- [drive:directory] (or the LW: assigned directory if the destination
- 2nd parameter is not specified) for the scene, image and object files.
-
- CopyScene.rexx checks a Lightwave Scene file to make sure that
- the file names referenced in the scene do indeed exist and are
- then copied to a destination of your choice. You can first
- ASSIGN that destination as a drive called LW: as that is what
- this script file uses as the destination if none is specified.
- (Or the assignment can be made more permanent in the
- user-startup Amiga file.)
-
- For example:
-
- ASSIGN LW: WORK:TOASTER/3D
- rx CopyScene DF0:MYSCENE.LWSCN
-
- would copy the myscene.lwscn file from drive DF0: and all
- files in the DF0: drive/directory structures referenced by the
- myscene.lwscn file to the proper directories on
- work:toaster/3d
-
- ASSIGN LW: DF0:
- rx CopyScene work:toaster/3d/scenes/my.scene
-
- would copy the my.scene and all its referenced files to the
- proper directories on the drive DF0:
-
- Thus it is possible by ASSIGNing the proper destination (LW:)
- to copy scnenes and files from hard drive to floppy or floppy
- to hard drive.
-
- NOTE: If you do not like the LW: assignment and would like to
- change the destination drive:directory, specify that location
- as a second parameter and Copyscene will change the default to
- use it (thus the LW: assignment is not necessary).
-
- rx CopyScene work:toaster/3d/scenes/my.scene DF0:
-
- CopyScene.rexx will create any neccessary directories on the
- ASSIGNed LW: drive (or specified destination path) if they do
- not exist such as (/IMAGES, /OBJECTS, /SCENES, etc.)
-
- The NullObject object is also created automatically in the
- destination /objects directory.
-
- The scene is also copied in a modified state to the \scenes
- destination. The modified copy of the scene file has the new
- references to the destination of the copied files.
-
- An error message is displayed if a file is not found that is
- referenced by the scene file, however, the CopyScene.rexx
- script will continue. Some files or file references not found
- are really OK since they may be references for example to
- where saved output (RGB images, ANIMs, etc.) will go. (They
- may also not have a drive:destination which LW layout will
- default to load from its supplied /objects,etc. directories
- but will be an error for the CopyScene script.)
-
- */
-
- /* TRACE(RESULTS) */
-
- OPTIONS RESULTS
-
- parse arg parm
- if arg() = 0 then call syntax()
- file = word(parm,1)
- if (words(parm) = 2) then dest = word(parm,2)
- else dest = 'LW:'
-
- if (right(dest,1)~= ':') then dest = dest||'/'
-
- if ~exists(dest) then call syntax()
- if ~exists(file) then call syntax()
-
- if (index(file,':') ~= 0) then do
- temp = translate(file," ","/:"," ")
- tempwords = words(temp)
- name = word(temp,tempwords)
- source = left(file,length(file)-length(name))
- end
- else source = pragma('D')
- if (right(source,1) ~= ':') then do
- if (right(source,1) ~= '/') then source = source||'/'
- end
-
- if ~show('L',"rexxsupport.library") then do
- if addlib('rexxsupport.library',0,-30,0) then
- say "Added rexxsupport.library."
- else do
- say "Error: addlib() of rexxsupport.library failed."
- exit 10
- end
- end
-
- open('infile',file,'R')
- instring=readln('infile')
-
- if (pos('LWSC',instring) ~= 1) then do
- close('infile')
- say file' is not a LW scene file!'
- exit(10)
- end
-
- say
- say '[Input Scene File Name]'file
-
- call newdir(dest)
- call makenull(dest)
-
- temp = translate(file," ","/:"," ")
- tempwords = words(temp)
- nameonly = word(temp,tempwords)
- outscn = dest||"scenes/"||nameonly
- say '[Output Scene File Name]'outscn
-
- open('outfile',outscn,'W')
- writeln('outfile',instring)
-
- do while eof('infile')=0
- instring = readln('infile')
- lwcmd = word(instring,1)
- c = index(lwcmd,'Load')
- if (index(instring,':') ~= 0) then do
- if (index(instring,'/') ~= 0) then c = c + 1
- end
- if (c > 0) then do
- filename = word(instring,2)
- if (index(instring,':') = 0) then do
- if (left(filename,1) ~= '/') then filename = source||filename
- else filename = source||strip(filename,'L','/')
- end
- temp = upper(translate(filename," ","/:"," "))
- c = showlist('A',word(temp,1))
- c = c + showlist('H',word(temp,1))
- if (c = 0) then do
- say instring
- call errmsg('Volume Not Mounted - ERROR')
- end
- else if (~exists(filename)) then do
- if (upper(word(temp,words(temp))) = "NULLOBJECT") then do
- say instring '[OK] NullObject already copied.'
- instring = lwcmd||" "||dest||"/Objects/NullObject"
- end
- else do
- temp = translate(filename," ","/:"," ")
- tempwords = words(temp)
- name = word(temp,tempwords)
- objname = source||'objects/'||name
- if (exists(objname)) then do
- say filename 'exists as' objname
- filename = objname
- call copyfile()
- end
- else do
- say (instring)
- call errmsg('File Not Found - ERROR')
- end
- end
- end
- else do
- say instring ' [OK]'
- call copyfile()
- end
- end
- writeln('outfile',instring)
- end
- close('infile')
- close('outfile')
- say
- say '<--- CopyScene Completed -->'
- exit 0
-
- copyfile: PROCEDURE EXPOSE source dest filename lwcmd instring
- OPTIONS RESULTS
- temp = translate(filename," ","/:"," ")
- tempwords = words(temp)
- nameonly = word(temp,tempwords)
- dir = ""
- if (index(lwcmd,"Image") ~= 0) then dir = 'images/'
- if (index(lwcmd,"Texture") ~= 0) then dir = 'textures/'
- if (index(lwcmd,"Object") ~= 0) then dir = 'objects/'
- if (index(lwcmd,"Frame") ~= 0) then dir = 'frames/'
- if (index(lwcmd,"Surface") ~= 0) then dir = 'surfaces/'
- if (dir = "") then do
- say "Unknown LW Scene Command Type -> "lwcmd
- call errmsg('File may not be copied to the proper directory - ERROR')
- end
- destname = dest||dir||nameonly
- instring = lwcmd||' '||destname
- if (index(lwcmd,"LoadObject") ~= 0) then call readlwob()
- else do
- say 'Copying file' filename 'to' destname
- if (~exists(destname)) then do
- address command
- 'copy 'filename' 'destname''
- address
- end
- else call errmsg('Copy not done - file already existed - WARNING')
- end
- return 0
-
- call errmsg('Volume Not Mounted - ERROR')
-
- newdir: procedure
- parse arg DIR
- OPTIONS RESULTS
- if (exists(DIR||'images') = 0) then do
- address command
- 'makedir 'DIR'images'
- address
- end
- if (exists(DIR||'objects') = 0) then do
- address command
- 'makedir 'DIR'objects'
- address
- end
- if (exists(DIR||'frames') = 0) then do
- address command
- 'makedir 'DIR'frames'
- address
- end
- if (exists(DIR||'textures') = 0) then do
- address command
- 'makedir 'DIR'textures'
- address
- end
- if (exists(DIR||'surfaces') = 0) then do
- address command
- 'makedir 'DIR'surfaces'
- address
- end
- if (exists(DIR||'scenes') = 0) then do
- address command
- 'makedir 'DIR'scenes'
- address
- end
- if (exists(DIR||'motions') = 0) then do
- address command
- 'makedir 'DIR'motions'
- address
- end
- if (exists(DIR||'previews') = 0) then do
- address command
- 'makedir 'DIR'previews'
- address
- end
- if (exists(DIR||'bitmaps') = 0) then do
- address command
- 'makedir 'DIR'bitmaps'
- address
- end
- return 0
-
- syntax:
- say
- say 'Syntax: rx CopyScene [drive:directory/]LW-Scene-File [drive:directory]'
- say
- say ' Note: The source file parameter must exist and you must either '
- say ' assign LW: to a drive:directory (which will be used as'
- say ' a default destination if none is specified) or you must'
- say ' specify a second parameter which will be used as the'
- say ' destination Drive:[directory]'
- say
- exit 10
-
- makenull: procedure
- parse arg DIR
- OPTIONS RESULTS
- h1 = '46 4f 52 3d 00 00 00 28 4C 57 4F 42 50 4E 54 53'X
- h2 = '00 00 00 0C 00 00 00 00 00 00 00 00 00 00 00 00'X
- h3 = '53 52 46 53 00 00 00 00 50 4F 4C 53 00 00 00 00'X
- null = h1||h2||h3
- open('output',DIR||'objects/'||'NullObject','W')
- writech('output',null)
- close('output')
- return 0
-
- readlwob: PROCEDURE EXPOSE source dest destname filename
- OPTIONS RESULTS
-
- open('lwobfile',filename,'R')
- objstring = readch('lwobfile',12)
-
- type = substr(objstring,9,4)
-
- if (type ~= "LWOB") then do
- close('lwobfile')
- say filename
- call errmsg('This is not a LW Object file! - ERROR')
- return 10
- end
-
- form = substr(objstring,1,4)
- length = c2d(substr(objstring,5,4),4)
- length = length + 8
-
- say 'Reading from' filename
- /* say 'Object file length is' length 'bytes' */
-
- open('lwobout',destname,'W')
- say 'Copying to ' destname
- writech('lwobout',objstring)
-
- do while eof('lwobfile')=0
- objstring=readch('lwobfile',8)
- if (eof('lwobfile') = 1) then break
- writech('lwobout',objstring)
- chunk = substr(objstring,1,4)
- length = c2d(substr(objstring,5,4),4)
- /* say 'Chunk Type is' chunk 'with a length of' length 'bytes' */
- if (chunk ~= "SURF") then do
- do while(length>0)
- /*
- NOTE: There is a maximum limit to the readch() length which
- is 65535. Therefore if the chunk size is greater than
- this limit, multiple reads are necessary.
- */
- objstring = readch('lwobfile',length)
- len = length(objstring)
- writech('lwobout',objstring)
- length = length - len
- end
- end
- else do
- objstring = readch('lwobfile',length)
- surfacepos = pos('00'x,objstring,1)
- surface = substr(objstring,1,(surfacepos-1))
- surfacepos = surfacepos + (surfacepos // 2) + 1
- say 'Surface Name:' surface
- do while (surfacepos < length)
- subchunk = substr(objstring,surfacepos,4)
- /* say 'Subchunk ' subchunk */
- surfacepos = surfacepos + 4
- len = c2d(substr(objstring,surfacepos,2),4)
- surfacepos = surfacepos + 2
- image = ""
- if (subchunk = "TIMG") then do
- image = strip(substr(objstring,surfacepos,len),'T','00'x)
- say 'Texture Image ->' image
- end
- if (subchunk = 'RIMG') then do
- image = strip(substr(objstring,surfacepos,len),'T','00'x)
- say 'Reflection Image ->' image
- end
- if (image = "(none)") then image = ""
- if (image ~= "") then do
- if (index(image,':') = 0) then do
- if (left(image,1) ~= '/') then fullimage = source||image
- else fullimage = source||strip(image,'L','/')
- end
- else fullimage = image
- temp = translate(fullimage," ","/:"," ")
- tempwords = words(temp)
- name = word(temp,tempwords)
- directory = left(fullimage,length(fullimage)-length(name))
- if (~exists(directory)) then do
- if (exists(source||"images")) then fullimage = source||'images/'||name
- end
- if (index(image,"(sequence)",1) ~= 0) then do
- temp = translate(image," ","/:"," ")
- tempwords = words(temp)
- nameonly = word(temp,tempwords-1)
- destimage = dest||'Images/'||nameonly||' (sequence)'
- if (len > length(destimage)) then do
- objstring = overlay(destimage,objstring,surfacepos,len,'00'x)
- say image 'overlayed by' destimage
- end
- else call errmsg('Image name not Overlayed since new name is longer! - ERROR')
- destimage = dest||'images/'
- fullimage = strip(overlay("#?",fullimage,pos("(sequence)",fullimage,1)-1,11,' '),'T')
- say 'Copying file' fullimage 'to' destimage
- address command
- 'copy 'fullimage' 'destimage''
- address
- end
- else if (exists(fullimage)) then do
- temp = translate(image," ","/:"," ")
- tempwords = words(temp)
- nameonly = word(temp,tempwords)
- destimage = dest||'Images/'||nameonly
- if (len > length(destimage)) then do
- objstring = overlay(destimage,objstring,surfacepos,len,'00'x)
- say image 'overlayed by' destimage
- end
- else call errmsg('Image name not Overlayed since new name is longer! - ERROR')
- say 'Copying file' fullimage 'to' destimage
- if (~exists(destimage)) then do
- address command
- 'copy 'fullimage' 'destimage''
- address
- end
- else call errmsg('No copy done - File already existed - WARNING')
- end
- else do
- say fullimage
- call errmsg('File Not Found - ERROR')
- end
- end
- surfacepos = surfacepos + len
- end
- writech('lwobout',objstring)
- end
- end
-
- close('lwobfile')
- close('lwobout')
- return 0
-
- errmsg: procedure
- parse arg msg
- lenmsg = length(msg) - 1
- errmsg = '|___________________________________________________________________________'
- errmsg = overlay(msg,errmsg,length(errmsg)-lenmsg,lenmsg+1)
- say errmsg
- return 0
-